package jmine.tec.di.type;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * {@link TypeConverter} para {@link URL}.
 * 
 * @author Rafael Volpato
 * @date Dec 7, 2010
 */
public class URLTypeConverter implements TypeConverter<URL> {

    /**
     * {@inheritDoc}
     */
    public boolean isTypeCompatible(Class<?> declaredRawType) {
        return URL.class == declaredRawType;
    }

    /**
     * {@inheritDoc}
     */
    public URL convert(String value, Class<?> desiredType) throws TypeConvertionException {
        try {
            return new URL(value);
        } catch (MalformedURLException e) {
            throw new TypeConvertionException(e, URL.class, value);
        }
    }
}
